﻿@{
    ViewBag.Title = "员工列表";
    Layout = "~/Views/MasterPage.cshtml";
    ViewBag.FirstPage = "人事管理";
    ViewBag.LastPage = "员工列表";
    
}
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<style>
    .am-btn-group am-btn-group-xs a {
        color: blue;
    }

        .am-btn-group am-btn-group-xs a :hover {
            color: orange;
            cursor: pointer;
        }
</style>
<div class="am-g">
    <div class="am-u-md-6 am-cf">
        <div class="am-fl am-cf">
            <div class="am-btn-toolbar am-fl">
                <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default" id="btnAdd"><span class="am-icon-plus"></span>新增</button>
                    <button type="button" class="am-btn am-btn-default" id="btnExcel"><span class="am-icon-save"></span>导入Excel</button>

                </div>

                <div class="am-form-group am-margin-left am-fl">
                </div>
            </div>
        </div>
    </div>
    <div class="am-u-md-3 am-cf">
        <div class="am-fr">
            <div class="am-input-group am-input-group-sm">
                <input type="text" class="am-form-field">
                <span class="am-input-group-btn">
                    <button class="am-btn am-btn-default" type="button">搜索</button>
                </span>
            </div>
        </div>
    </div>
</div>
<div class="am-g">
    <div class="am-u-sm-12">
        <form class="am-form">
            <table class="am-table am-table-striped am-table-hover table-main">
                <thead>
                    <tr>
                        @*  <th class="table-check">
                            <input type="checkbox"></th>
                        <th class="table-id">ID</th>*@
                        <th class="table-title">账号</th>
                        <th class="table-type">姓名</th>
                        <th class="table-author">性别</th>
                        <th class="table-date">户籍</th>
                        <th class="table-date">状态</th>
                        <th class="table-set">操作</th>
                    </tr>
                </thead>
                <tbody>
                    @{
                     
                        var list = Model as List<Model.OA_UserAccount>;
                        foreach (var item in list)
                        {
                            var userBasic = BLL.EmployeeManager.GetUserBasic(item.Id);
                            if (userBasic != null)
                            {
                        <tr>
                            @* <td>
                                <input type="checkbox"></td>
                            <td>@item.Id</td>*@
                            <td><a style="color:blue" name="UserDetail" data-id="@item.Id" data-value="@userBasic.RealName">@item.Account</a></td>
                            <td>@userBasic.RealName</td>
                            <td>
                                @if (userBasic.Sex == true)
                                {
                                    @:女
                               }
                                else
                                {
                                    @:男
                               }

                            </td>
                            <td>@userBasic.Address1</td>
                            <td>
                                @if (item.IsEnable)
                                {
                                    @:<a data-id="@item.Id" style="color:green;cursor:pointer">启用</a>
                                }
                                else
                                {
                                    @:<a data-id="@item.Id" style="color:red;cursor:pointer" >禁用</a>
                                }

                            </td>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a>编辑</a>&emsp;
                                        <a name="btnAuth" data-id="@item.Id">分配角色</a>&emsp;
                                        @{
                                if (item.IsEnable)
                                {
                                            @:<a name="Enable" data-id="@item.Id" data-value="false" style="cursor:pointer">禁用</a>
                                            }
                                else
                                {
                                            @:<a name="Enable" data-id="@item.Id" data-value="true" style="cursor:pointer">启用</a>
                                            }
                                        }

                                        <a>删除</a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                            }
                        }
                           
                    }


                </tbody>
            </table>
            <div class="am-cf">
                共 @list.Count 条记录
  <div class="am-fr">
      <ul class="am-pagination">
          <li class="am-disabled"><a href="#">«</a></li>
          <li class="am-active"><a href="#">1</a></li>
          <li><a href="#">2</a></li>
          <li><a href="#">3</a></li>
          <li><a href="#">4</a></li>
          <li><a href="#">5</a></li>
          <li><a href="#">»</a></li>
      </ul>
  </div>
            </div>
            <hr>
            @*<p>注：.....</p>*@
        </form>
    </div>

</div>
<script src="/Source/layui/layui.js"></script>
<script src="/Source/layui/layui.all.js"></script>
<link href="/Source/layui/css/layui.css" rel="stylesheet" />
<script>

    $(function () {
        $("a[name='btnAuth']").click(function () {
            layer.open({
                type: 2,
                title: "分配角色",
                area: ['500px', '350px'],
                content: "/Role/Index/" + $(this).attr("data-id") //分配角色页面
            });
        });

        //查看员工详情信息
        $("a[name='UserDetail']").click(function () {
            layer.open({
                type: 2,
                title: $(this).attr("data-value") + "_详细信息",
                area: ['500px', '350px'],
                content: "/Employee/UserDetail/" + $(this).attr("data-id") //员工详情页面
            });
            //tab层

            
        });

        //新增
        $("#btnAdd").click(function () {
            layer.open({
                type: 2,
                title: "新增信息",
                area: ['650px', '550px'],
                content: "/Employee/Insert" //员工详情页面
            });
        });


        //启用或者禁用

        $("a[name='Enable']").click(function () {
            var id = $(this).attr("data-id");
            var result = $(this).attr("data-value");
            $.ajax({
                url: "/Employee/ToggleStatus",
                type: "post",
                data: { "Id": id, "IsEnable": result },
                success: function (returnData) {
                    console.log(returnData)
                    if (returnData.Code == 1) {
                        layer.alert((result == "false" ? "禁用" : "启用") + "成功!!!");
                        setInterval(function () {
                            window.location.href = "/Employee/Index";
                        }, 3000);
                    } else {
                        layer.alert("操作失败！！！");
                    }
                }, error: function () {

                }
            });
        });

        //数据导入到Excel
        $("#btnExcel").click(function () {
            $.ajax({
                url: "/Employee/DataToExcel",
                type: "post",
                data: {},
                success: function (returnData) {
                    if (returnData) {
                        layer.alert("导入成功！");
                    } else {
                        layer.alert("导入失败！");
                    }
                }, error: function () {

                }
            });
        });

    })
</script>
